<div class="wide form">

	<?php
	$properties = array(
		'id'=>'language-form',
		'htmlOptions'=>array('enctype'=>'multipart/form-data'),
		'enableAjaxValidation'=>true,
	);
	$form = $this->beginWidget('CActiveForm', $properties);
	if (!$virgin) {
		echo $form->hiddenField($chapter, 'mangaId');
		echo $form->hiddenField($chapter, 'id');
		echo $form->hiddenField($model, 'value');
		if (Yii::app()->user->isGuest) {
			echo $form->hiddenField($model, 'name');
			echo $form->hiddenField($model, 'email');
		}
	}
	?>

	<?php echo $form->errorSummary(array($chapter, $model, $page)); ?>

	<div class="row">
		<?php
		echo $form->labelEx($model, 'file');
		if ($model->isNewRecord) {
			$baseUrl = Yii::app()->request->baseUrl;
			$remove = CHtml::image(
					"$baseUrl/images/toolbars/cross-script.png", 'Remove'
			);
			$properties = array(
				'name'=>'images',
				'max'=>10,
				'accept'=>'jpg|jpeg|gif|png',
				'remove'=>$remove,
			);
			$this->widget('CMultiFileUpload', $properties);
		} else {
			echo $form->fileField($model, 'file');
		}
		echo $form->error($model, 'file');
		?>
	</div>

	<?php if ($virgin): ?>

		<div class="row">
			<?php
			echo $form->labelEx($chapter, 'mangaId');
			$data = Manga::model()->listData();
			$htmlOptions = array(
				'encode'=>false,
				'prompt'=>'Select 4-Koma',
				'ajax'=>array(
					'type'=>'POST',
					'url'=>$this->createUrl('chapter/ajaxTag'),
					'update'=>'#' . CHtml::activeId($chapter, 'id'),
				),
			);
			echo $form->dropDownList($chapter, 'mangaId', $data, $htmlOptions);
			echo $form->error($chapter, 'mangaId');
			?>
		</div>

		<div class="row">
			<?php
			echo $form->labelEx($chapter, 'id');
			echo $form->dropDownList($chapter, 'id', $chapterListData);
			echo $form->error($chapter, 'id');
			?>
		</div>

	<?php endif; ?>

	<?php if ($model->isNewRecord && $virgin): ?>
		<div class="row">
			<label>&nbsp;</label>
			Page will be auto incremented if you upload multiple image.<br/>
			<label>&nbsp;</label>
			Sub page (b, c, d, ...) only applies to first page.<br>
			<label>&nbsp;</label>
			Upload one image only if you want to upload sub page to avoid
			confusion.
		</div>
	<?php endif; ?>

	<div class="row">
		<?php
		echo $form->labelEx($page, 'sequence');
		echo $form->textField(
			$page, 'sequence', array('size'=>7, 'maxlength'=>5)
		);
		$data = array('b'=>'b', 'c'=>'c', 'd'=>'d', 'e'=>'e');
		$htmlOptions = array(
			'encode'=>false,
			'prompt'=>'',
		);
		echo $form->dropDownList($page, 'subSequence', $data, $htmlOptions);
		echo $form->error($page, 'sequence');
		echo $form->error($page, 'subSequence');
		?>
	</div>

	<?php if ($virgin): ?>

		<div class="row">
			<?php
			echo $form->labelEx($model, 'value');
			$properties = array(
				'model'=>$model,
				'attribute'=>'value',
				'source'=>array(
					'English',
					'Japanese',
					'Chinese',
				),
				'htmlOptions'=>array('placeholder'=>'Language'),
				'options'=>array('showAnim'=>'fold'),
			);
			$this->widget(
				'zii.widgets.jui.CJuiAutoComplete', $properties
			);
			echo $form->error($model, 'value');
			?>
		</div>

		<?php if (Yii::app()->user->isGuest): ?>

			<div class="row">
				<?php
				echo $form->labelEx($model, 'name');
				echo $form->textField(
					$model, 'name', array('size'=>60, 'maxlength'=>255)
				);
				echo $form->error($model, 'name');
				?>
			</div>

			<div class="row">
				<?php
				echo $form->labelEx($model, 'email');
				echo $form->textField(
					$model, 'email', array('size'=>60, 'maxlength'=>128)
				);
				echo $form->error($model, 'email');
				?>
			</div>

		<?php endif; ?>

	<?php endif; ?>

	<div class="row buttons">
		<?php
		echo CHtml::submitButton($model->isNewRecord ? 'Upload' : 'Update');
		?>
	</div>

	<?php $this->endWidget(); ?>

</div><!-- form -->